package com.wnxy.sdd.controller;

import com.wnxy.sdd.common.result.Result;
import com.wnxy.sdd.model.vo.SubjectTreeVo;
import com.wnxy.sdd.service.ISubjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    private ISubjectService subjectService;
    /**
     * Excel导入
     * @RequestPart 方便swagger测试；如果不写swagger那里不显示文件上传表单
     */
    @PostMapping("/import/excel")
    @ApiOperation("Excel导入")
    public Result importExcel(@RequestPart("file") MultipartFile file){
        subjectService.importExcel(file);
        return Result.ok();
    }

    /**
     * 查询课程分类
     * @return
     */
    @GetMapping
    @ApiOperation("查询课程一级分类、二级分类")
    public Result findSubjects(){
        List<SubjectTreeVo> list = subjectService.findSubjects();
        return Result.ok(list);
    }
}
